package com.atguigu.gmall.realtime.dws.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: KeyWordUtil
 * Description:
 * 分词工具类
 * @Create 2024/4/24 11:10
 */
public class KeywordUtil {
    //分词
    public static List<String> analyze(String text) {
        List<String> wordList = new ArrayList<>();

        //分词器对象
        StringReader reader = new StringReader(text);
        //智能分词true
        IKSegmenter ik = new IKSegmenter(reader, true);
        try {
            Lexeme lexeme = null;
            while ((lexeme = ik.next()) != null) {
                String keyword = lexeme.getLexemeText();
                wordList.add(keyword);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return wordList;
    }

    /*public static void main(String[] args) {
        System.out.println(analyze("苗智广"));
    }*/

}
